<?php

use App\Http\Controllers\Article\Merchant\CategoryController;
use App\Http\Controllers\Article\Web\ArticleCategoryController;
use App\Http\Controllers\Article\Web\ArticleController;
use App\Http\Controllers\Article\Web\ArticleRecommendController;
use App\Http\Controllers\Article\Web\ArticleStatisticsController;
use App\Http\Middleware\OpenShop\FeishuWebAuth;
use App\Http\Middleware\OpenShop\MerchantAppAuth;
use App\Http\Middleware\OpenShop\UserPermissionAuth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Article\Merchant\ArticleController as MerchantArticleController;
use App\Http\Controllers\Article\Merchant\ArticleRecommendController as MerchantArticleRecommendController;


/**
 * 运营后台
 */
Route::middleware([FeishuWebAuth::class, UserPermissionAuth::class])->prefix("backend")->group(function () {

    /**
     * 文章分类(专题)
     */
    Route::prefix('category')->group(function () {
        //数据统计
        Route::get("statistics", [ArticleCategoryController::class, "groupStatistics"]);
        //热门专题列表
        Route::get("hotList", [ArticleCategoryController::class, "hotList"]);
        // 专题新增
        Route::post("add", [ArticleCategoryController::class, "add"]);
        // 专题列表
        Route::get("list", [ArticleCategoryController::class, "list"]);
        // 专题详情
        Route::get("detail/{id}", [ArticleCategoryController::class, "detail"])->where('id', '[0-9]+');
        // 专题删除
        Route::delete("del/{id}", [ArticleCategoryController::class, "del"])->where('id', '[0-9]+');
        // 专题修改
        Route::post("update/{id}", [ArticleCategoryController::class, "update"])->where('id', '[0-9]+');
        // 专题排序
        Route::post("sort/{id}", [ArticleCategoryController::class, "sort"])->where('id', '[0-9]+');
        // 专题文章列表
        Route::get("articleList/{cid}", [ArticleCategoryController::class, "articleList"])->where('cid', '[0-9]+');
        // 专题文章添加
        Route::post("articleAdd/{cid}", [ArticleCategoryController::class, "articleAdd"])->where('cid', '[0-9]+');
        // 专题文章移除
        Route::delete("articleDel/{cid}", [ArticleCategoryController::class, "articleDel"])->where('cid', '[0-9]+');
        // 专题文章排序
        Route::post("articleSort/{cid}", [ArticleCategoryController::class, "articleSort"])->where('cid', '[0-9]+');
        // 专题置顶
        Route::put("putTop/{id}", [ArticleCategoryController::class, "putTop"])->where('id', '[0-9]+');
    });

    /**
     * 文章推荐栏目(专题)
     */
    Route::prefix('article/recommend')->group(function () {
        // 推荐列表
        Route::get("list", [ArticleRecommendController::class, "list"]);
        // 推荐详情
        Route::get("detail", [ArticleRecommendController::class, "detail"]);
        // 新增推荐
        Route::post("add", [ArticleRecommendController::class, "add"]);
        // 修改推荐
        Route::post("update", [ArticleRecommendController::class, "update"]);
        // 推荐预览
        Route::get("preview", [ArticleRecommendController::class, "preview"]);
        // 推荐专栏删除
        Route::post("delete", [ArticleRecommendController::class, "delete"]);
        // 推荐专栏上下架
        Route::post("patch", [ArticleRecommendController::class, "patch"]);

    });

    /**
     * 内容管理
     */
    Route::prefix("article")->group(function () {
        //添加 内容
        Route::post("", [ArticleController::class, "add"]);
        //启用｜禁用 内容
        Route::put("/status/{id}", [ArticleController::class, "status"])->where('id', '[0-9]+');
        //内容排序
        Route::put("/sort/{id}", [ArticleController::class, "sort"])->where('id', '[0-9]+');
        //内容置顶
        Route::put("/putTop/{id}", [ArticleController::class, "putTop"])->where('id', '[0-9]+');
        //内容列表
        Route::get("/list", [ArticleController::class, "list"])->where('id', '[0-9]+');
        //编辑内容
        Route::put("/{id}", [ArticleController::class, "update"])->where('id', '[0-9]+');
        //内容详情
        Route::get("/{id}", [ArticleController::class, "detail"])->where('id', '[0-9]+');
        //删除内容
        Route::delete("/{id}", [ArticleController::class, "del"])->where('id', '[0-9]+');
        //内容热榜置顶
        Route::put("/putHotTop/{id}", [ArticleController::class, "putHotTop"])->where('id', '[0-9]+');
    });

    /**
     * 数据统计
     */
    Route::prefix("statistics")->group(function () {
        Route::get("/list", [ArticleStatisticsController::class, "list"]);                    //总数据
        Route::get("/articleList", [ArticleStatisticsController::class, "articleList"]);      //文章列表
        Route::get("/getArticleList", [ArticleStatisticsController::class, "getArticleList"]);//文章数据统计列表
    });


});


/**
 * 商家端
 */
Route::middleware([MerchantAppAuth::class])->prefix("merchant")->group(function () {

    /**
     * 内容管理
     */
    Route::prefix("article")->group(function () {
        //首页信息流
        Route::get("/indexList", [MerchantArticleController::class, "indexList"]);
        //操作分类列表
        Route::get("/operateList", [MerchantArticleController::class, "operateList"]);
        //视频｜文章详情
        Route::get("/{id}", [MerchantArticleController::class, "detail"])->where('id', '[0-9]+');
        // 推荐栏目
        Route::get("/recommend/list", [MerchantArticleRecommendController::class, "lists"]);
        // 推荐视频列表
        Route::get("/recommend/videoList", [MerchantArticleController::class, "videoList"]);
    });

    //商家-交互操作(点赞、分享、收藏)
    Route::post("operate", [MerchantArticleController::class, "operate"]);

    // 商家-首页数据埋点记录
    Route::post('click', [MerchantArticleController::class, 'click']);

    /**
     * 专题
     */
    Route::prefix("category")->group(function () {
        //专题操作
        Route::post("/operate", [CategoryController::class, "operate"]);
        //专题详情
        Route::get("/{id}", [CategoryController::class, "detail"])->where('id', '[0-9]+');
        //操作分类列表
        Route::get("/operateList", [CategoryController::class, "operateList"]);
    });

    Route::prefix("home")->group(function () {
        // 首页分类
        Route::get("/tab", [MerchantArticleController::class, "tab"]);
        // 首页分类数据
        Route::get("/tabContent", [MerchantArticleController::class, "tabContent"]);
    });
});


/**
 * 对外
 */
Route::prefix("outside")->group(function () {
    /**
     * 内容管理
     */
    Route::prefix("article")->group(function () {
        //视频｜文章详情
        Route::get("/{id}", [MerchantArticleController::class, "detail"])->where('id', '[0-9]+');
    });

    /**
     * 专题管理
     */
    Route::prefix("category")->group(function () {
        //专题详情
        Route::get("/{id}", [CategoryController::class, "detail"])->where('id', '[0-9]+');
    });
});
